package com.rh.security;


import com.rh.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 密码处理器
 * PasswordEncoder是用来专门做密码加密的,里面有加密和比对的方法
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    /**
     * 无参构造
     */
    public DefaultPasswordEncoder() { this(-1);}
    /**
     * 有参构造
     */
    public DefaultPasswordEncoder(int strength) {}

    /**
     * 把密码用MD5进行加密
     */
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString());
    }
    /**
     * 密码比对的方法
     */
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(rawPassword.toString()));
    }
}